package com.neuedu.controller;

import com.neuedu.common.ServerResponse;
import com.neuedu.entity.Prescription;
import com.neuedu.service.PrescriptionService;
import com.neuedu.vo.DrugVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api("处方模块")
@RestController
@RequestMapping("/prescription")
public class PrescriptionController {

    @Resource
    private PrescriptionService prescriptionService;

    @RequestMapping("/add")
    public ServerResponse add(@RequestBody List<Prescription> prescriptionList){

        //System.out.println(prescriptionList);

        //调用业务方法
        if(prescriptionService.addPrescription(prescriptionList)){
            return ServerResponse.success("开具处方成功");
        }else{
            return ServerResponse.success("开具处方失败");
        }
    }


    @ApiOperation("获取药品列表---收费和取药时使用")
    @GetMapping("/list/{registerId}/{status}")
    public ServerResponse list(@PathVariable String registerId, @PathVariable int status) {

        System.out.println("registerId=" + registerId);
        System.out.println("status=" + status);

        //调用业务方法
        List<DrugVO> drugVOList = prescriptionService.getDrugList(registerId, status);

        return ServerResponse.success("").data("drugVOList", drugVOList);
    }

    @ApiOperation("药品缴费")
    @PutMapping("/fee/{registerId}")
    public ServerResponse fee(@PathVariable String registerId) {

        //调用业务方法
        if(prescriptionService.feeDrugList(registerId)){
            return ServerResponse.success("药品缴费成功");
        }else{
            return ServerResponse.error("药品缴费失败");
        }
    }

    @ApiOperation("取药")
    @PutMapping("/take/{registerId}")
    public ServerResponse take(@PathVariable String registerId) {

        //调用业务方法
        if(prescriptionService.takeDrugList(registerId)){
            return ServerResponse.success("取药成功");
        }else{
            return ServerResponse.error("取药失败");
        }
    }
}
